package singleResponsibility;

class User2 {
    private String name;
    private String email;

    public User2(String name, String email) {
        this.name = name;
        this.email = email;
    }

    public String getName() {
        return name;
    }

    public String getEmail() {
        return email;
    }

    public void register() {
        // 注册用户
        System.out.println("User registered: " + name);
    }
}

class EmailService {
    public void sendEmail(String email, String message) {
        // 发送电子邮件
        System.out.println("Email sent to: " + email + " with message: " + message);
    }
}

public class UserService {
    private EmailService emailService;

    public UserService(EmailService emailService) {
        this.emailService = emailService;
    }

    public void registerUser(User2 user) {
        user.register();
        emailService.sendEmail(user.getEmail(), "Welcome " + user.getName() + "!");
    }

    public static void main(String[] args) {
        EmailService emailService = new EmailService();
        UserService userService = new UserService(emailService);

        User2 user = new User2("John Doe", "john.doe@example.com");
        userService.registerUser(user);
    }
}
